
import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService, TreeNode } from 'primeng/api';
import { CreateOrEditBopTreeModalComponent } from '@app/admin/bop/create-or-edit-boptree-modal.component';
import { OrganizationUnitsTreeComponent } from '@app/admin/shared/organization-unit-tree.component';
import { DomSanitizer } from '@angular/platform-browser';
import {
    BopContentEditDto, BopContentServiceProxy, BopNodeServiceProxy, PQualitWorkStepDto,
    QualityPlatformServiceProxy, RbopContentInfoDto, RprocessesDto, RTechFileHeaderDto,
    OperationHistoryServiceProxy, EditFileServiceProxy
} from '@shared/service-proxies/service-proxies';
import { Paginator } from 'primeng/components/paginator/paginator';
import * as moment from 'moment';
import DiffMatchPatch from 'diff-match-patch';
import Quill from 'quill'
import { controlNameBinding } from '@angular/forms/src/directives/reactive_directives/form_control_name';
@Component({
    selector: 'createOrEditBopManageModal',
    templateUrl: './bop-manage.component.html',
    styleUrls: ['./bop-manage.component.less'],

})
export class BopManageComponent extends AppComponentBase {

    @ViewChild('createOrEditModal') modal: ModalDirective;
    @ViewChild('organizationUnitTree') organizationUnitTree: OrganizationUnitsTreeComponent;
    @ViewChild('paginator') paginator: Paginator;
    //第一个参数是对应子组件的selector，第二个参数自定义显示到html页面，第三个参数是引入路径
    @ViewChild('createOrEditBopTreeModal') createOrEditBopTreeModal: CreateOrEditBopTreeModalComponent;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Input() parentInfo: any;//父级节点信息  
    active = false;
    saving = false;
    treeForm = {};
    advancedFiltersAreShown = false;
    loading: boolean;
    loadingtree: boolean;
    isReceived = true;
    isCompleted = false;
    anyncing = false;
    filterText = '';
    files2: any;//树形结构
    selectedFiles: TreeNode;
    ischeckTree: any;//当前点击节点
    bopContent: BopContentEditDto = new BopContentEditDto();
    btInfo: RbopContentInfoDto = new RbopContentInfoDto();//部套
    btInfoDate = undefined;// 部套新增时间
    btInfoNewDate = undefined;// 部套新增时间
    btInfoReturnDate = undefined;// 部套回传时间
    processFile: RTechFileHeaderDto = new RTechFileHeaderDto();//工艺规程
    workStepData: [];//工步动态表List
    workStepHeader: any;//工步动态表Header
    isSon: boolean = false;// 树结构儿子1
    isParent: boolean = true;// 树结构父级0
    isGrandSon: boolean = false;// 树结构孙子2
    isGrandSons: boolean = false;// 树结构孙子3
    titleName = '发次描述';
    titleLable = '发次';
    //数据导出需要的参数
    exportData: any;
    // ischangekey:0;//右侧tab切换 0为部套 1为工艺规程
    //右侧工序信息
    processInfo: RprocessesDto = new RprocessesDto();
    //右侧工步信息
    workstepInfo: PQualitWorkStepDto = new PQualitWorkStepDto();
    check = [];
    workStepCheck = [];
    video = [];
    tableData = [];
    tableDataUse = [];
    tableForRecord = [];
    displayModal = false;
    displayModalForUser = false;
    displayModalForCheckPerson = false;
    displayModalForCheck = false;
    personData = [];
    changeData = [];
    cansoleData = [];
    checkData = [];
    checkTitle = [];
    dpt = new DiffMatchPatch();
    OtherTag: string[] = ['&nbsp;']
    invisibleUnicodeRangeStart: number = 0xE865
    invisibleUnicodeRangeEnd: number = 0xF8FF
    tagMap: any = {}
    mapLength: number = 0
    constructor(
        injector: Injector,
        private sanitizer: DomSanitizer,
        private _qualityPlatformServiceProxy: QualityPlatformServiceProxy,
        private _bopNodeServiceProxy: BopNodeServiceProxy,
        private _bopContentServiceProxy: BopContentServiceProxy,
        private _editFileServiceProxy: EditFileServiceProxy,
        private _operationHistoryService: OperationHistoryServiceProxy
    ) {
        super(injector);
    }
    init() {
    }
    getTrStyle(row) {
        if (row.newRow) {
            return 'tr-add-style'
        }
        if (row.deletedRow) {
            return 'tr-del-style'
        }
        return '';
    }
    getChangeTableData(row, type) {
        if (row == undefined || type == undefined) {
            return '';
        }

        if (row.newRow || row.deletedRow) {
            return row[type]
        }

        let data = undefined;
        for (const item of row.editFileTableDataInfos) {
            if (item.fieldName == type) {
                data = item;
            }
        }

        if (data != undefined) {
            data.newValue = data.newValue == null ? data.newValue : data.newValue.replace(/\s*/g, "");
            data.value = data.value == null ? data.value : data.value.replace(/\s*/g, "");
            if ((data.newValue == null || data.newValue == '') && (data.value == null || data.value == '')) {
                return ''
            }
            if ((data.newValue == null || data.newValue == '') && (data.value != null && data.value != '')) {
                //return this.sanitizer.bypassSecurityTrustHtml('<del class="del-style">' + data.value + '</del><style>.requirement del{ background: #ffe6e6} .requirement ins{ background: #e6ffe6}</style>')
                return this.sanitizer.bypassSecurityTrustHtml(data.value + '<style>.requirement del{ background: #ffe6e6} .requirement ins{ background: #e6ffe6}</style>')

                // return data.value;
            }
            if ((data.value == null || data.value == '') && (data.newValue != '' && data.newValue != null)) {
                return this.sanitizer.bypassSecurityTrustHtml('<ins class="add-style">' + data.newValue + '</ins><style>.requirement del{ background: #ffe6e6} .requirement ins{ background: #e6ffe6}</style>')
            }


            let dmp = new DiffMatchPatch();
            let processesExplain = data.value
            let updateProcessesExplain = data.newValue
            let diffs = dmp.diff_main(processesExplain, updateProcessesExplain)
            dmp.diff_cleanupSemantic(diffs)
            let diffOutput = ''
            for (let x = 0; x < diffs.length; x++) {
                let tagsHtml = this.insertTagsForOperation(diffs[x][1], diffs[x][0])
                diffOutput += tagsHtml
            }
            return this.sanitizer.bypassSecurityTrustHtml(diffOutput + '<style>.requirement del{ background: #ffe6e6} .requirement ins{ background: #e6ffe6}</style>')
        }

    }
    getChangeData(old, newData) {
        if (old == null) {
            old = '';
        }
        let dmp = new DiffMatchPatch();
        let processesExplain = this.convertHtmlToDiffableString(old)
        let updateProcessesExplain = this.convertHtmlToDiffableString(newData)
        let diffs = dmp.diff_main(processesExplain, updateProcessesExplain)
        dmp.diff_cleanupSemantic(diffs)
        let diffOutput = ''
        for (let x = 0; x < diffs.length; x++) {
            let tagsHtml = this.insertTagsForOperation(diffs[x][1], diffs[x][0])
            diffOutput += this.convertDiffableBackToHtml(tagsHtml)
        }
        return this.sanitizer.bypassSecurityTrustHtml(diffOutput + '<style>.requirement del{ background: #ffe6e6} .requirement ins{ background: #e6ffe6}</style>')
    }
    convertDiffableBackToHtml(diffableString) {
        let htmlString = ''
        for (let x = 0; x < diffableString.length; x++) {
            let charCode = diffableString.charCodeAt(x)
            if (!this.isInvisibleUnicode(charCode)) {
                htmlString += diffableString[x]
                continue
            }
            let tagString = this.tagMap[diffableString[x]]
            if (tagString === undefined) {
                htmlString += diffableString[x]
            }
            else {
                htmlString += tagString
            }
        }
        return htmlString
    }
    insertTagsForOperation(diffableString, operation) {
        // ###因为需要处理img标签,不能跳过
        // 如果所有字符都是标签则直接返回
        // let n = -1
        // do {
        //     n++
        // } while (this.isInvisibleUnicode(diffableString.charCodeAt(n)))
        // if (n >= diffableString.length) {
        //     return diffableString
        // }
        let openTag = ''
        let closeTag = ''
        let imgOpenTag = ''
        let imgCloseTag = '</div>'
        if (operation === 1) {
            openTag = `<ins class="add-style">`
            closeTag = '</ins>'
            imgOpenTag = '<div style="display: inline-block;box-shadow: 0 0 2px 2px green;">'
        }
        else if (operation === -1) {
            openTag = `<del  class="del-style">`
            closeTag = '</del>'
            imgOpenTag = '<div style="display: inline-block;box-shadow: 0 0 2px 2px red;">'
        }
        else {
            return diffableString
        }
        let outputString = openTag
        let isOpen = true
        for (let x = 0; x < diffableString.length; x++) {
            if (!this.isInvisibleUnicode(diffableString.charCodeAt(x))) {
                // 如果是常规字符,则添加opentag
                if (!isOpen) {
                    outputString += openTag
                    isOpen = true
                }
                // 添加到输出字符内
                outputString += diffableString[x]
            }
            else {
                // 如果是tag字符,添加closetag
                if (isOpen) {
                    outputString += closeTag
                    isOpen = false
                }
                //获取原标签内容
                let tag = this.tagMap[diffableString[x]]
                if (tag.includes('img')) {
                    //如果是img则添加img对应的增加\删除标签
                    outputString += imgOpenTag + diffableString[x] + imgCloseTag
                } else {
                    //其它情况直接写回标签
                    outputString += diffableString[x]
                }

            }
        }
        if (isOpen)
            outputString += closeTag
        return outputString
    }
    isInvisibleUnicode(charCode: any) {
        return charCode >= this.invisibleUnicodeRangeStart && charCode <= this.invisibleUnicodeRangeEnd
    }
    addInvisibleUnicodeCode(tag: string) {
        if (this.invisibleUnicodeRangeStart + this.mapLength > this.invisibleUnicodeRangeEnd) {
            console.error('标签类型过多,超出可用编码范围')
        }
        let invisibleUnicodeCharacter = String.fromCharCode(this.invisibleUnicodeRangeStart + this.mapLength)
        this.tagMap[tag] = invisibleUnicodeCharacter
        this.tagMap[invisibleUnicodeCharacter] = tag
        this.mapLength++
        return invisibleUnicodeCharacter
    }
    convertOtherTag(htmlString: string) {
        if (!htmlString)
            return htmlString
        for (let tag of this.OtherTag) {
            htmlString = htmlString.replace(new RegExp(tag, 'g'), this.tagMap[tag])
        }
        return htmlString
    }
    convertHtmlToDiffableString(htmlString: string) {
        htmlString = this.convertOtherTag(htmlString)
        let diffableString = ''
        let offset = 0
        while (offset < htmlString.length) {
            let tagStart = htmlString.indexOf('<', offset)
            if (tagStart < 0) {
                diffableString += htmlString.substring(offset)
                break
            }
            else {
                let tagEnd = htmlString.indexOf('>', tagStart)
                if (tagEnd < 0) {
                    // 无效html
                    // 在标签的开头截断
                    console.error('无效的html,将会截断字符串')
                    diffableString += htmlString.substring(offset, offset + tagStart - offset)
                    break
                }
                let tagString = htmlString.substring(tagStart, tagStart + tagEnd + 1 - tagStart)
                // 判断标签是否已经映射
                let unicodeCharacter = this.tagMap[tagString]
                if (unicodeCharacter === undefined) {
                    // 如果没映射,增加映射
                    unicodeCharacter = this.addInvisibleUnicodeCode(tagString)
                }
                diffableString += htmlString.substring(offset, offset + tagStart - offset)
                diffableString += unicodeCharacter
                offset = tagEnd + 1
            }
        }
        return diffableString
    }
    getUser(item) {
        let msg = item ? item.split('，') : [];
        // let result = [];
        // for (const i of msg) {
        //     let data = i.split('_');
        //     result.push(data);
        // }
        let rs = [];
        for (const item of msg) {
            let msg = item.split('*');
            let data = { name: undefined, time: undefined, url: undefined };
            data.name = msg[0];
            data.time = msg[1];
            data.url = msg[2];
            rs.push(data);
        }
        return rs;
    }
    //打开弹窗
    onShown(): void {
    }
    //获取树结构
    getTreeInfo(): void {
        this.loadingtree = true;
        this._qualityPlatformServiceProxy.getQualityTreeList(this.parentInfo.id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                //建立父级节点
                this.files2 = [{ id: this.parentInfo.id, key: -1, nodeDrawingNo: this.parentInfo.drawingNo, nodeName: this.parentInfo.modelName, model: this.parentInfo.model, lotNo: this.parentInfo.lotNo, stageSign: this.parentInfo.stageSign, children: result ? result : [] }];
                this.expandAll();
                this.ischeckTree = {};
                this.loadingtree = false;
            });
    }
    //点击树节点
    nodeSelect(event): void {
        // //如果是父级节点则不允许操作
        // if(event.node.key==-1){
        //      return;
        // }
        this.ischeckTree = event.node;
        if (this.ischeckTree.nodeLevel == undefined) {
            this.titleLable = '发次描述';
            this.titleName = '发次';
            this.isSon = false;
            this.isGrandSon = false;
            this.isParent = true;
            this.isGrandSons = false;
        }
        if (this.ischeckTree.nodeLevel == 1) {
            this.titleLable = '芯级描述';
            this.titleName = '芯级';
            this.isSon = true;
            this.isGrandSon = false;
            this.isParent = false;
            this.isGrandSons = false;
        }
        if (this.ischeckTree.nodeLevel == 2) {
            this.titleLable = '部套描述';
            this.titleName = '部套';
            this.isSon = false;
            this.isGrandSon = true;
            this.isParent = false;
            this.isGrandSons = false;
        }
        if (this.ischeckTree.nodeLevel == 3) {
            this.titleLable = '工作项目描述';
            this.titleName = '工作项目';
            this.isSon = false;
            this.isGrandSon = false;
            this.isParent = false;
            this.isGrandSons = true;
        }
        //如果未关联 则差右侧
        if (parseInt(this.ischeckTree.nodeLevel) != 8 && parseInt(this.ischeckTree.nodeLevel) != 9) {
            this._qualityPlatformServiceProxy.getQualityBopContentInfoList(event.node.id)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.btInfo = result;
                    this.btInfoDate = undefined;
                    this.btInfoNewDate = undefined;
                    this.btInfoReturnDate = undefined;
                    if (result.relationDate != undefined) {
                        this.btInfoDate = moment(result.relationDate).format('YYYY-MM-DD HH:mm:ss');
                    }
                    if (result.exportDate != undefined) {
                        this.btInfoNewDate = moment(result.exportDate).format('YYYY-MM-DD HH:mm:ss');
                    }
                    if (result.returnDate != undefined) {
                        this.btInfoReturnDate = moment(result.returnDate).format('YYYY-MM-DD HH:mm:ss');
                    }
                    var tarDiv = document.getElementById("pane1");
                    if (tarDiv != null) {
                        while (tarDiv.hasChildNodes()) {
                            tarDiv.removeChild(tarDiv.firstChild);
                        }
                        var newDiv = document.createElement("div");
                        newDiv.innerHTML = this.btInfo.techniqueExplain;
                        tarDiv.appendChild(newDiv);
                    }
                });
            this._qualityPlatformServiceProxy.getTechFileHeader(event.node.id)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.processFile = result;
                });
            if (event.node.rtechniqueEntityId) {
                this._operationHistoryService.getTechOperationLogList(event.node.rtechniqueEntityId, 2)
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.tableData = result;
                    })
                this._operationHistoryService.getTechOperationLogList(event.node.rtechniqueEntityId, 1)
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.tableDataUse = result;
                    })
            }
        }
        //已关联查出下面工序和工步
        if (this.ischeckTree.isRelation == 1) {
            this.getChange(event.node.rtechniqueEntityId == null ? event.node.id : event.node.rtechniqueEntityId);
            this.getUserChange(event.node.rtechniqueEntityId == null ? event.node.id : event.node.rtechniqueEntityId);
            this.loadingtree = true;
            this._qualityPlatformServiceProxy.getQualityWorkStepList(event.node.id)
                .pipe(finalize(() => { this.loadingtree = false; }))
                .subscribe(result => {
                    let rowInfo = this.getTreeRecursion(this.files2, this.ischeckTree.id);
                    rowInfo.children = result;

                });
        }
        //工序查看右侧
        if (parseInt(this.ischeckTree.nodeLevel) == 8) {
            this.check = []
            //abp.ui.setBusy(undefined, '', 1);
            this._qualityPlatformServiceProxy.getRprocessesById(event.node.id)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.processInfo = result;
                    let item = this.processInfo.processesCharacteristic.split('|');
                    this.check = item;
                    this.check.splice(this.check.length - 1, 1);
                    // abp.ui.clearBusy();
                });
        }
        //工步查看右侧
        if (parseInt(this.ischeckTree.nodeLevel) == 9) {
            // abp.ui.setBusy(undefined, '', 1);
            this._qualityPlatformServiceProxy.getWorkStepOut(event.node.id)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    if (result.workStepOut.workStepCharacteristic != null) {
                        this.workStepCheck = result.workStepOut.workStepCharacteristic.split('|');
                        this.workStepCheck.splice(this.workStepCheck.length - 1, 1);
                    }
                    this.workstepInfo = result;
                    //abp.ui.clearBusy();
                    this.onTabChange({ index: 0 });

                });
        }
    }
    checkRecordWatch(row) {
        this.displayModalForCheck = true;
        let data = row;
        let innerData = {};
        this.checkData = [];
        this.checkTitle = row.clearSignatureDataStruces;
        for (const item of data.clearSignatureRowDatas) {
            if (item.fieldName == 'FirstOperator' || item.fieldName == 'SecondOperator' || item.fieldName == 'ThirdOperator'
                || item.fieldName == 'FourthOperator' || item.fieldName == 'FifthOperator') {
                if (item.value != null && item.value != '') {
                    let checker = undefined;
                    checker = JSON.parse(item.value);
                    innerData[item.fieldName] = checker[0].user + '/' + moment(checker[0].date).format('YYYY-MM-DD HH:mm:ss');
                } else {
                    innerData[item.fieldName] = '';
                }
            } else if (item.fieldName == 'PhotoNo') {
                //处理他+路径
                let data = item.value.split(',');
                let video = [];
                let picture = [];
                for (const photo of data) {
                    if (photo.endsWith('mp4')) {
                        video.push(photo);
                    } else {
                        picture.push(photo);
                    }
                }
                let rs = [{ video: video, picture: picture }];
                innerData[item.fieldName] = rs;
            } else {
                innerData[item.fieldName] = item.value;
            }
        }
        this.checkData.push(innerData);
        console.log(this.checkData);


    }
    getUserChange(id) {
        this._editFileServiceProxy.getSignatureList(id)
            .pipe(finalize(() => { }))
            .subscribe(result => {

                this.cansoleData = result;
            });
    }
    getChange(id) {
        this._editFileServiceProxy.getEditFileListByRtechId(id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                let data = [];
                data = result;
                for (const item of data) {
                    item.checkPerson = [];
                    item.confirmPerson = [];
                    if (item.editConfirmSignature) {
                        let confirmItem = JSON.parse(item.editConfirmSignature);
                        console.log(confirmItem);
                        for (const confirm of confirmItem) {
                            let data = {
                                checker: undefined,
                                checkStatus: undefined,
                                checkMsg: undefined,
                                checkMoment: undefined
                            }
                            data.checker = confirm.fullName;
                            data.checkMoment = confirm.date;
                            data.checkMsg = confirm.name;
                            item.confirmPerson.push(data)
                        }
                    }
                    if (item.firstOperator != null) {
                        let data = {
                            checker: undefined,
                            checkStatus: undefined,
                            checkMsg: undefined,
                            checkMoment: undefined
                        }
                        data.checker = item.firstOperator_DisplayName;
                        data.checkStatus = item.firstOperatorDate_DisplayName;
                        data.checkMsg = JSON.parse(item.firstOperator);
                        data.checkMoment = item.firstOperator_Date;
                        item.checkPerson.push(data);
                    }
                    if (item.secondOperator != null) {
                        let data = {
                            checker: undefined,
                            checkStatus: undefined,
                            checkMsg: undefined,
                            checkMoment: undefined
                        }
                        data.checker = item.secondOperator_DisplayName;
                        data.checkStatus = item.secondOperatorDate_DisplayName;
                        data.checkMsg = JSON.parse(item.secondOperator);
                        data.checkMoment = item.secondOperator_Date;
                        item.checkPerson.push(data);
                    }
                    if (item.thirdOperator != null) {
                        let data = {
                            checker: undefined,
                            checkStatus: undefined,
                            checkMsg: undefined,
                            checkMoment: undefined
                        }
                        data.checker = item.thirdOperator_DisplayName;
                        data.checkStatus = item.thirdOperatorDate_DisplayName;
                        data.checkMsg = JSON.parse(item.thirdOperator);
                        data.checkMoment = item.thirdOperator_Date;
                        item.checkPerson.push(data);
                    }
                    if (item.fourthOperator != null) {
                        let data = {
                            checker: undefined,
                            checkStatus: undefined,
                            checkMsg: undefined,
                            checkMoment: undefined
                        }
                        data.checker = item.fourthOperator_DisplayName;
                        data.checkStatus = item.fourthOperatorDate_DisplayName;
                        data.checkMsg = JSON.parse(item.fourthOperator);
                        data.checkMoment = item.fourthOperator_Date;
                        item.checkPerson.push(data);
                    }
                    if (item.fifthOperator != null) {
                        let data = {
                            checker: undefined,
                            checkStatus: undefined,
                            checkMsg: undefined,
                            checkMoment: undefined
                        }
                        data.checker = item.fifthOperator_DisplayName;
                        data.checkStatus = item.fifthOperatorDate_DisplayName;
                        data.checkMsg = JSON.parse(item.fifthOperator);
                        data.checkMoment = item.fifthOperator_Date;
                        item.checkPerson.push(data);
                    }
                    for (const table of item.editFileProcessInfos) {
                        for (const a of table.editFileStepInfos) {
                            for (const b of a.editFileTableInfos) {
                                for (const dataRow of b.editFileRowInfos) {
                                    for (const inner of dataRow.editFileTableDataInfos) {
                                        if (dataRow.newRow) {
                                            //新增
                                            dataRow[inner.fieldName] = this.sanitizer.bypassSecurityTrustHtml("<p style='color:#000000'>" + (inner.newValue == null ? '' : inner.newValue) + "</p>");
                                        }
                                        if (dataRow.deletedRow) {
                                            //删除
                                            dataRow[inner.fieldName] = this.sanitizer.bypassSecurityTrustHtml("<p style='color:#fff'>" + inner.value + "</p>");
                                        }
                                        if (!dataRow.newRow && !dataRow.deletedRow) {
                                            //修改
                                            if (inner.newValue == null) {
                                                dataRow[inner.fieldName] = `<p>` + inner.value + `</p>`;
                                            } else {
                                                if (inner.value == '' || inner.value == null || inner.value == undefined) {
                                                    dataRow[inner.fieldName] = this.sanitizer.bypassSecurityTrustHtml("<div><span style='color: #66DD00;'>" + inner.newValue + "</span></div>");
                                                } else {
                                                    dataRow[inner.fieldName] = this.sanitizer.bypassSecurityTrustHtml("<div><span style='text-decoration:line-through;color: red;'>" + inner.value + "</span><br><span style='color: #66DD00;'>"
                                                        + inner.newValue + "</span></div>");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                this.tableForRecord = data;
            });
    }
    getRecordStatus(status) {
        switch (status) {
            case 0:
                return '编辑中';
            case 1:
                return '签字中';
            case 2:
                return '签字完成';
            case 3:
                return '签字待确认';
            case 3:
                return '确认完成';
            default:
                break;
        }
    }
    recordWatch(row) {

        this.displayModal = true;
        this.changeData = row;
    }
    msgHide(event) {
        this.changeData = [];
    }
    personWatch(row, type) {
        if (type == 0) {
            this.displayModalForUser = true;
        } else {
            this.displayModalForCheckPerson = true
        }
        this.personData = row;
    }
    userHide(event) {
        this.checkData = [];
        this.personData = [];
    }
    // //分页获取动态表数据
    // getTableList() {
    //     abp.ui.setBusy(undefined, '', 1);
    //     this._qualityPlatformServiceProxy.getWorkStepOut(this.ischeckTree.node.id)
    //         .pipe(finalize(() => { }))
    //         .subscribe(result => {
    //             this.workstepInfo = result;
    //             abp.ui.clearBusy();
    //             this.onTabChange({ index: 0 });

    //         });
    // }

    //处理图片
    getImage(item) {
        let imageList = item ? item.split(',') : []
        let result = []
        imageList.forEach((e, i) => {
            if (e.includes('.mp4')) {
            } else {
                // let a = e.split('_');
                // a[a.length - 1] = a[a.length - 1].replace('thumbnail', '');
                // let rs = a.join('');
                let rs = e.replace('_thumbnail', '');
                result.push({
                    source: rs,
                    thumbnail: rs,
                    title: ''
                })
            }
        })
        // imageList.forEach((e, i) => {
        //     if (e.includes('.mp4')) {
        //     } else {
        //         let a = e.split('_');
        //         a[a.length - 1] = a[a.length - 1].replace('thumbnail', '');
        //         let rs = a.join('');
        //         result.push({
        //             source: rs,
        //             thumbnail: rs,
        //             title: ''
        //         })
        //     }
        // })
        return result
    }
    getVideo(item) {
        let imageList = item ? item.split(',') : []
        let result = []
        imageList.forEach((e, i) => {
            if (e.includes('.mp4')) {
                result.push({
                    source: e,
                    thumbnail: e,
                    title: ''
                })
            }
        })
        return result
    }
    // 递归循环树级结构 获取对象 通过物料ID 递归
    getTreeRecursion(data, current) {
        var result = null;
        if (!data) {
            // return; 中断执行
            return;
        }
        for (var i in data) {
            if (result != null) {
                break;
            }
            var item = data[i];
            // 通过id找到树结构相应节点 找到则跳出
            if (item.id == current) {
                result = item;
                break;
            } else if (item.children && item.children.length > 0) {
                result = this.getTreeRecursion(item.children, current);
            }
        }
        return result;
    }

    show(): void {
        this.active = true;
        this.parentInfo.creationTime = moment(this.parentInfo.creationTime).format('YYYY-MM-DD HH:mm:ss');
        this.modal.show();
    }

    expandAll() {
        this.files2.forEach((node) => {
            this.expandRecursive(node, true);
        });
    }

    collapseAll() {
        this.files2.forEach((node) => {
            this.expandRecursive(node, false);
        });
    }

    private expandRecursive(node: TreeNode, isExpand: boolean) {
        node.expanded = isExpand;
        if (node.children) {
            node.children.forEach((childNode) => {
                this.expandRecursive(childNode, isExpand);
            });
        }
    }
    close(): void {
        this.tableForRecord = [];
        this.active = false;
        this.files2 = [];
        this.btInfo = new RbopContentInfoDto();
        this.processFile = new RTechFileHeaderDto();
        this.btInfoDate = undefined;
        this.btInfoNewDate = undefined;
        this.btInfoReturnDate = undefined;
        this.workStepData = undefined;
        this.workStepHeader = undefined;
        this.workstepInfo = new PQualitWorkStepDto();
        this.modal.hide();
    }
    //tab 切换工步动态表
    onTabChange(event) {
        this.workStepHeader = this.workstepInfo.tableNameDictionary[event.index];
        this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[event.index].tableKey];
    }

}
